<?php

class EquipModel extends Model {

    public function getequips($uid = 0)
	{
        $uid = intval($uid);
        if (!$uid) return array('ecode' => ERR302);

        $ret = &daocall("equip", "getequips", array($uid));
        if ($ret === false || !is_array($ret)) return array("ecode" => ERR601);
		else return array("ecode" => SUCCESS, 'ret' => &$ret);
    }
	

	//开启装备升级
	public function upstuff($uid = 0, $eid = 0)
	{
		$uid = intval($uid);
		$eid = intval($eid);
        if (!$uid || !$eid) return array('ecode' => ERR302);

		$eq = &daocall("equip", "getequips", array($uid));
		if(!$eq || !$eq[$eid]) return array('ecode' => ERR603);
		$eq = $eq[$eid];

		$conf = &load_conf("pub:equip");
		if(!$conf || !$conf["equip"] || !$conf["equip"][$eq["etype"]]) return array('ecode' => ERR603);
		$conf = $conf["equip"];

		if(!$conf[$eq["etype"]]["grow"]) return array('ecode' => ERR605);

		if(intval($conf[$eq["etype"]]["grow"][$eq["elv"]]) > intval($eq["exp"])) return array('ecode' => ERR606);

		$stf = &daocall("stuff", "getstuffs", array($uid));
        if ($stf === false || !is_array($stf) || intval($stf["s1"]) < 1) return array("ecode" => ERR607);

		$stf["s1"] --;
		if(!daocall("stuff", "setstuff", array($uid, "s1", $stf["s1"]))) return array("ecode" => ERR604);

		$eq["elv"] ++;
		if(!daocall("equip", "setequip", array($uid, $eid, array("elv" => $eq["elv"], "exp" => 0)))) return array("ecode" => ERR604);

		return array("ecode" => SUCCESS);
	}
}
?>